home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / APLocation / Sources / MacOS_UAppleEvents.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  23.5 KB  |  773 lines

  1. /*==================================================================
  2.     File:        MacOS_UAppleEvents.h
  3.  
  4.     Contains:    AppleEvent utility classes.
  5.  
  6.     Written by:    Ed Reed
  7.  
  8.     Copyright:    © 1999 Connectix Corporation
  9. ==================================================================*/
  10.  
  11. #pragma once
  12.  
  13. #include "MacOS_AppleEventUtils.h"
  14. #include "MacOS_ConnectixUtils.h"
  15. #include "MacOS_Namespaces.h"
  16. #include "MacOS_UAppleEventTraits.h"
  17.  
  18. #ifndef __AEDATAMODEL__
  19. #include <AEDataModel.h>
  20. #endif
  21.  
  22. #ifndef __AEOBJECTS__
  23. #include <AEObjects.h>
  24. #endif
  25.  
  26. #ifndef __AEREGISTRY__
  27. #include <AERegistry.h>
  28. #endif
  29.  
  30. #ifndef __ERRORS__
  31. #include <Errors.h>
  32. #endif
  33.  
  34. #ifndef __PROCESSES__
  35. #include <Processes.h>
  36. #endif
  37.  
  38. #pragma options align=mac68k
  39.  
  40.  
  41. CTX_Begin_Namespace_MacOS
  42.  
  43.  
  44. /*******************************************************************
  45.     FORWARD DECLARATIONS
  46. *******************************************************************/
  47.  
  48. class AEDescriptor;
  49. class AEToken;
  50. class AEObjSpecifier;
  51. class AEDescriptorList;
  52. class AEDescriptorRecord;
  53. class AEAppleEvent;
  54.  
  55. /*******************************************************************
  56.     CONSTANTS
  57. *******************************************************************/
  58.  
  59. typedef struct AESuppressCreate {int ignore; } AESuppressCreate;
  60.  
  61. const AESuppressCreate    kAESuppressCreate = {0};
  62. const AEDesc            kAENullDescriptor = {typeNull, NULL};
  63.  
  64. /*******************************************************************
  65.     TYPE/CLASS DEFINTIONS
  66. *******************************************************************/
  67.  
  68. /*------------------------------------------------------------------
  69.     AEDescriptor
  70. ------------------------------------------------------------------*/
  71.  
  72. #pragma mark class AEDescriptor
  73.  
  74. class AEDescriptor : public AEDesc
  75. {
  76. public:
  77.     /* Constructors & Destructor */
  78.             AEDescriptor(void) { descriptorType = typeNull; dataHandle = NULL; }
  79.             AEDescriptor(const AEDesc & inAEDesc);
  80.             AEDescriptor(DescType inType, const void * inData, Size inSize);
  81.             AEDescriptor(DescType inType, Handle inData);
  82.             AEDescriptor(DescType inType);
  83.  
  84.             ~AEDescriptor(void) { ::AEDisposeDesc(this); }
  85.  
  86.     /* Assignment Methods */
  87.     OSErr    AssignDesc(const AEDesc & inAEDesc);
  88.  
  89.     OSErr    Assign(DescType inType, const void * inData, Size inSize);
  90.     OSErr    Assign(DescType inDataType, Handle inHandle);
  91.     template <typename _Type>
  92.     OSErr    Assign(const _Type & inValue)
  93.             {
  94.                 return Assign(AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  95.             }
  96.     template <typename _Type>
  97.     OSErr    Assign(DescType inType, const _Type & inValue)
  98.             {
  99.                 return Assign(inType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  100.             }
  101.  
  102.     /* Data Access Methods */
  103.     OSErr    GetData(DescType inType, void * outData, Size inSize) const
  104.             {
  105.                 if (descriptorType != inType)
  106.                     return paramErr;
  107. #if TARGET_API_MAC_CARBON
  108.                 ::AEGetDescData(this, outData, inSize);
  109. #else
  110.                 ::BlockMoveData(*dataHandle, outData, inSize);
  111. #endif
  112.                 return noErr;
  113.             }
  114.     template <typename _Type>
  115.     OSErr    GetData(_Type & outValue) const
  116.             {
  117.                 if (descriptorType != AEDescriptorTraits<_Type>::kDescriptorType)
  118.                     return paramErr;
  119.                 outValue = **reinterpret_cast<const _Type**>(dataHandle);
  120.                 return noErr;
  121.             }
  122.     template <typename _Type>
  123.     OSErr    GetData(DescType inType, _Type & outValue) const
  124.             {
  125.                 if (descriptorType != inType)
  126.                     return paramErr;
  127.                 outValue = **reinterpret_cast<const _Type**>(dataHandle);
  128.                 return noErr;
  129.             }
  130.     
  131.     OSErr    GetCString(char * outCString, Size inMaxLength) const;
  132.     OSErr    GetPString(StringPtr outPString, Size inMaxLength = kPascalStringMaxLength) const;
  133.  
  134.     /* Coercion Methods */
  135.     OSErr    CoerceToDesc(DescType inDesiredType, AEDesc & outDesc) const
  136.             {
  137.                 return CTX_MacOS::CoerceDesc(this, inDesiredType, &outDesc);
  138.             }
  139.     template <typename _Type>
  140.     OSErr    CoerceTo(_Type & outValue) const
  141.             {
  142.                 OSErr status;
  143.                 AEDescriptor coercedValue;
  144.  
  145.                 status = CoerceToDesc(AEDescriptorTraits<_Type>::kDescriptorType, coercedValue);
  146.                 if (status == noErr)
  147.                     status = coercedValue.GetData(outValue);
  148.                 return status;
  149.             }
  150.     template <typename _Type>
  151.     OSErr    CoerceTo(DescType inDesiredType, _Type & outValue) const
  152.             {
  153.                 OSErr status;
  154.                 AEDescriptor coercedValue;
  155.  
  156.                 status = CoerceToDesc(inDesiredType, coercedValue);
  157.                 if (status == noErr)
  158.                     status = coercedValue.GetData(inDesiredType, outValue);
  159.                 return status;
  160.             }
  161.  
  162.     /* Object Specifier Resolution Methods */
  163.     OSErr    Resolve(AEDesc & outDesc, SInt16 inFlags = kAEIDoMinimum)
  164.             {
  165.                 return CTX_MacOS::ResolveAEParameter(this, &outDesc, inFlags);
  166.             }
  167.  
  168.     /* Miscellaneous Accessors */
  169.     DescType    GetType(void) const { return descriptorType; }
  170.  
  171.     Size GetDataSize(void) const
  172.     {
  173.         return GetAEDescDataSize(*this);
  174.     }
  175.  
  176.     bool    IsNull() const            { return (descriptorType == typeNull); }
  177.     
  178.     bool    IsNotNull() const        { return (descriptorType != typeNull); }
  179. };
  180.  
  181. /*------------------------------------------------------------------
  182.     TAEDescriptor
  183. ------------------------------------------------------------------*/
  184.  
  185. #pragma mark class TAEDescriptor
  186.  
  187. template <typename _Type>
  188. struct TAEDescriptor : public AEDescriptor
  189. {
  190. public:
  191.     /* Constructors & Destructor */
  192.             TAEDescriptor(const _Type & inValue)
  193.                 : AEDescriptor(AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue))
  194.             {
  195.             }
  196.  
  197.             TAEDescriptor(DescType inType, const _Type & inValue)
  198.                 : AEDescriptor(inType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue))
  199.             {
  200.             }
  201.  
  202. private:
  203.             TAEDescriptor();
  204. };
  205.  
  206. /*------------------------------------------------------------------
  207.     AEToken
  208. ------------------------------------------------------------------*/
  209.  
  210. #pragma mark class AEToken
  211.  
  212. class AEToken : public AEDesc
  213. {
  214. public:
  215.     /* Constructors & Destructor */
  216.                 AEToken(void) { descriptorType = typeNull; dataHandle = NULL; }
  217.  
  218.                 ~AEToken(void) { ::AEDisposeToken(this); }
  219.  
  220.     /* Data Access Methods */
  221.     template <typename _Type>
  222.     OSErr        GetData(_Type & outValue) const
  223.                 {
  224.                     if (descriptorType != AEDescriptorTraits<_Type>::kDescriptorType)
  225.                         return paramErr;
  226.                     outValue = **reinterpret_cast<const _Type**>(dataHandle);
  227.                     return noErr;
  228.                 }
  229.     template <typename _Type>
  230.     OSErr        GetData(DescType inType, _Type & outValue) const
  231.                 {
  232.                     if (descriptorType != inType)
  233.                         return paramErr;
  234.                     outValue = **reinterpret_cast<const _Type**>(dataHandle);
  235.                     return noErr;
  236.                 }
  237.  
  238.     /* Miscellaneous Accessors */
  239.     DescType    GetType() const { return descriptorType; }
  240.     Size        GetDataSize(void) const
  241.     {
  242.         return GetAEDescDataSize(*this);
  243.     }
  244.  
  245. private:
  246.  
  247.             AEToken(const AEDesc & inAEDesc);
  248.             AEToken(DescType inType, const void * inData, Size inSize);
  249.             AEToken(DescType inType, Handle inData);
  250. };
  251.  
  252. /*------------------------------------------------------------------
  253.     AEDescriptorList
  254. ------------------------------------------------------------------*/
  255.  
  256. #pragma mark class AEDescriptorList
  257.  
  258. class AEDescriptorList : public AEDescriptor
  259. {
  260.     friend class AEDescriptorRecord;
  261. public:
  262.     /* Constructors & Destructor */
  263.     explicit    AEDescriptorList(const AEDesc & inAEDesc);
  264.     explicit    AEDescriptorList(const AEDescriptorList & inAEDesc);
  265.                 AEDescriptorList(const void* inFactoringPtr = NULL, Size inSize = 0);
  266.  
  267.     /* Methods to Add Items to the List */
  268.     OSErr        PutItemDesc(const AEDesc& inDesc, SInt32 inIndex = 0)
  269.                 {
  270.                     return ::AEPutDesc(this, inIndex, &inDesc);
  271.                 }
  272.  
  273.     OSErr        PutItem(DescType inType, const void* inData, Size inSize, SInt32 inIndex = 0)
  274.                 {
  275.                     return ::AEPutPtr(this, inIndex, inType, inData, inSize);
  276.                 }
  277.     template <typename _Type>
  278.     OSErr        PutItem(const _Type & inValue, SInt32 inIndex = 0)
  279.                 {
  280.                     return PutItem(AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue), inIndex);
  281.                 }
  282.     template <typename _Type>
  283.     OSErr        PutItem(DescType inDataType, const _Type & inValue, SInt32 inIndex = 0)
  284.                 {
  285.                     return PutItem(inDataType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue), inIndex);
  286.                 }
  287.  
  288.     OSErr    PutCStringItem(const char * outCString, SInt32 inIndex = 0);
  289.     OSErr    PutPStringItem(ConstStringPtr outPString, SInt32 inIndex = 0);
  290.     OSErr    PutBooleanItem(Boolean inBool, SInt32 inIndex = 0);
  291.     
  292.     /* Methods to Retrieve Items from the List */
  293.     OSErr        GetItemDesc(SInt32 inIndex, DescType inDesiredType, AEDesc & outDesc) const
  294.                 {
  295.                     AEKeyword ignore;
  296.                     return ::AEGetNthDesc(this, inIndex, inDesiredType, &ignore, &outDesc);
  297.                 }
  298.  
  299.     OSErr        GetItem(SInt32 inIndex, DescType& ioType, void* outData, Size inSize) const
  300.                 {
  301.                     AEKeyword ignore;
  302.                     Size actualSize;
  303.                     return ::AEGetNthPtr(this, inIndex, ioType,
  304.                                                 &ignore, &ioType, outData, inSize, &actualSize);
  305.                 }
  306.     template <typename _Type>
  307.     OSErr        GetItem(SInt32 inIndex, _Type & outValue) const
  308.                 {
  309.                     DescType type = AEDescriptorTraits<_Type>::kDescriptorType;
  310.                     return GetItem(inIndex, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  311.                 }
  312.     template <typename _Type>
  313.     OSErr        GetItem(SInt32 inIndex, DescType inType, _Type & outValue) const
  314.                 {
  315.                     DescType type = inType;
  316.                     return GetItem(inIndex, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  317.                 }
  318.  
  319.     OSErr    GetCStringItem(SInt32 inIndex, char * outCString, Size inMaxLength);
  320.     OSErr    GetPStringItem(SInt32 inIndex, StringPtr outPString, Size inMaxLength = kPascalStringMaxLength);
  321.     OSErr    GetBooleanItem(    SInt32 inIndex, Boolean& outBoolean );
  322.     
  323.     /* Methods to Get Information on Items in the List */
  324.     Size        GetItemSize(SInt32 inIndex)
  325.                 {
  326.                     DescType type;
  327.                     Size actualSize;
  328.                     return ::AESizeOfNthItem(this, inIndex, &type, &actualSize) == noErr
  329.                             ? actualSize
  330.                             : 0;
  331.                 }
  332.     SInt32        CountItems(void) const
  333.                 {
  334.                     SInt32 count;
  335.                     return ::AECountItems(this, &count) == noErr ? count : 0;
  336.                 }
  337.  
  338. protected:
  339.                 AEDescriptorList(const AESuppressCreate& /* inAESuppressCreate */)
  340.                     : AEDescriptor()
  341.                 {
  342.                 }
  343. };
  344.  
  345. /*------------------------------------------------------------------
  346.     AEDescriptorRecord
  347. ------------------------------------------------------------------*/
  348.  
  349. #pragma mark class AEDescriptorRecord
  350.  
  351. class AEDescriptorRecord : public AEDescriptorList
  352. {
  353. public:
  354.     /* Constructors & Destructor */
  355.                 AEDescriptorRecord(const void* inFactoringPtr = NULL, Size inSize = 0);
  356.     explicit    AEDescriptorRecord(const AEDesc & inAEDesc);
  357.     explicit    AEDescriptorRecord(const AEDescriptorRecord & inAEDesc);
  358.  
  359.     /* Methods to Add Keyworded Items to the Record */
  360.     OSErr        PutKeyDesc(AEKeyword inKey, const AEDesc & inDesc)
  361.                 {
  362.                     return ::AEPutKeyDesc(this, inKey, &inDesc);
  363.                 }
  364.  
  365.     OSErr        PutKey(AEKeyword inKey, DescType inType, const void* inData, Size inSize)
  366.                 {
  367.                     return ::AEPutKeyPtr(this, inKey, inType, inData, inSize);
  368.                 }
  369.     template <typename _Type>
  370.     OSErr        PutKey(AEKeyword inKey, const _Type & inValue)
  371.                 {
  372.                     return PutKey(inKey, AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  373.                 }
  374.     template <typename _Type>
  375.     OSErr        PutKey(AEKeyword inKey, DescType inType, const _Type & inValue)
  376.                 {
  377.                     return PutKey(inKey, inType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  378.                 }
  379.  
  380.     OSErr    PutCStringKey(AEKeyword inKey, const char * outCString);
  381.     OSErr    PutPStringKey(AEKeyword inKey, ConstStringPtr outPString);
  382.  
  383.     /* Methods to Retrieve Keyworded Items from the Record */
  384.     OSErr        GetKeyDesc(AEKeyword inKey, DescType inDesiredType, AEDesc & outDesc) const
  385.                 {
  386.                     return ::AEGetKeyDesc(this, inKey, inDesiredType, &outDesc);
  387.                 }
  388.  
  389.     OSErr        GetKey(AEKeyword inKey, DescType& ioType, void* outData, Size inSize) const
  390.                 {
  391.                     Size actualSize;
  392.                     return ::AEGetKeyPtr(this, inKey, ioType, &ioType, outData, inSize, &actualSize);
  393.                 }
  394.     template <typename _Type>
  395.     OSErr        GetKey(AEKeyword inKey, _Type & outValue) const
  396.                 {
  397.                     DescType type = AEDescriptorTraits<_Type>::kDescriptorType;
  398.                     return GetKey(inKey, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  399.                 }
  400.     template <typename _Type>
  401.     OSErr        GetKey(AEKeyword inKey, DescType inType, _Type & outValue) const
  402.                 {
  403.                     DescType type = inType;
  404.                     return GetKey(inKey, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  405.                 }
  406.  
  407.     OSErr    GetCStringKey(AEKeyword inKey, char * outCString, Size inMaxLength);
  408.     OSErr    GetPStringKey(AEKeyword inKey, StringPtr outPString, Size inMaxLength = kPascalStringMaxLength);
  409.  
  410.     /* Methods to Get Information on Keyworded Items in the List */
  411.     Size        GetKeySize(AEKeyword inKey) const
  412.                 {
  413.                     DescType type;
  414.                     Size actualSize;
  415.                     return ::AESizeOfKeyDesc(this, inKey, &type, &actualSize) == noErr
  416.                         ? actualSize
  417.                         : 0;
  418.                 }
  419.  
  420.     /* Methods to Retrieve Indexed Items from the Record */
  421.     OSErr        GetItemDesc(SInt32 inIndex, DescType inDesiredType, AEKeyword & outKeyword, AEDesc & outDesc) const
  422.                 {
  423.                     return ::AEGetNthDesc(this, inIndex, inDesiredType, &outKeyword, &outDesc);
  424.                 }
  425.  
  426.     OSErr        GetItem(SInt32 inIndex, DescType& ioType, AEKeyword& outKeyword, void* outData, Size inSize) const
  427.                 {
  428.                     Size actualSize;
  429.                     return ::AEGetNthPtr(this, inIndex, ioType,
  430.                                                 &outKeyword, &ioType, outData, inSize, &actualSize);
  431.                 }
  432.     template <typename _Type>
  433.     OSErr        GetItem(SInt32 inIndex, AEKeyword & outKeyword, _Type & outValue) const
  434.                 {
  435.                     DescType type = AEDescriptorTraits<_Type>::kDescriptorType;
  436.                     return GetItem(inIndex, type, outKeyword, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  437.                 }
  438.  
  439. protected:
  440.                 AEDescriptorRecord(const AESuppressCreate& inAESuppressCreate)
  441.                     : AEDescriptorList(inAESuppressCreate)
  442.                 {
  443.                 }
  444.  
  445. };
  446.  
  447.  
  448. /*------------------------------------------------------------------
  449.     AEObjSpecifier
  450. ------------------------------------------------------------------*/
  451.  
  452. #pragma mark class AEObjSpecifier
  453.  
  454. class AEObjSpecifier : public AEDescriptorRecord
  455. {
  456. public:
  457.     AEObjSpecifier(
  458.         DescType        inDesiredClass,
  459.         DescType        inKeyForm,
  460.         const AEDesc&    inKeyData,
  461.         const AEDesc&    inContainer = kAENullDescriptor);
  462. };
  463.  
  464. /*------------------------------------------------------------------
  465.     AEAppleEvent
  466. ------------------------------------------------------------------*/
  467.  
  468. #pragma mark class AEAppleEvent
  469.  
  470. class AEAppleEvent : public AEDescriptorRecord
  471. {
  472. public:
  473.                 AEAppleEvent(    AEEventClass    inAEClass,
  474.                                 AEEventID        inAEEventID,
  475.                                 const AEDesc&    inTarget,
  476.                                 AEReturnID        inReturnID = kAutoGenerateReturnID,
  477.                                 AETransactionID    inTransactionID = kAnyTransactionID)
  478.                     : AEDescriptorRecord(kAESuppressCreate)
  479.                 {
  480.                     MakeAppleEvent(inAEClass, inAEEventID, inTarget, inReturnID, inTransactionID);
  481.                 }
  482.                 AEAppleEvent(    AEEventClass                inAEClass,
  483.                                 AEEventID                    inAEEventID,
  484.                                 const ProcessSerialNumber&    inTarget,
  485.                                 AEReturnID                    inReturnID = kAutoGenerateReturnID,
  486.                                 AETransactionID                inTransactionID = kAnyTransactionID);
  487.                 AEAppleEvent(    AEEventClass    inAEClass,
  488.                                 AEEventID        inAEEventID,
  489.                                 OSType            inSignature,
  490.                                 AEReturnID        inReturnID = kAutoGenerateReturnID,
  491.                                 AETransactionID    inTransactionID = kAnyTransactionID);
  492.                 AEAppleEvent();
  493.  
  494.     /* copy constructors */
  495.     explicit    AEAppleEvent(const AEDesc & inOriginal);
  496.     explicit    AEAppleEvent(const AEAppleEvent & inOriginal);
  497.  
  498.                 OSErr Send(    AEDesc&            outReply,
  499.                             AESendMode        inSendMode = kAECanInteract+kAECanSwitchLayer+kAEWaitReply,
  500.                             AESendPriority    inPriority = kAENormalPriority,
  501.                             SInt32            inTimeout = kAEDefaultTimeout,
  502.                             AEIdleUPP        inIdleProc = NULL,
  503.                             AEFilterUPP        inEventFilter = NULL) const
  504.                     {
  505.                         return ::AESend(this,
  506.                                         &outReply,
  507.                                         inSendMode,
  508.                                         inPriority,
  509.                                         inTimeout,
  510.                                         inIdleProc,
  511.                                         inEventFilter);
  512.                     }
  513.                 OSErr Send(    AESendMode        inSendMode = kAECanInteract+kAECanSwitchLayer,
  514.                             AESendPriority    inPriority = kAENormalPriority,
  515.                             SInt32            inTimeout = kAEDefaultTimeout,
  516.                             AEIdleUPP        inIdleProc = NULL,
  517.                             AEFilterUPP        inEventFilter = NULL) const
  518.                     {
  519.                         AEDesc ignore;
  520.                         return ::AESend(this,
  521.                                         &ignore,
  522.                                         (inSendMode&0xFFFFFFF0)|kAENoReply,
  523.                                         inPriority,
  524.                                         inTimeout,
  525.                                         inIdleProc,
  526.                                         inEventFilter);
  527.                     }
  528.     
  529.     
  530.     /* Methods to create an AppleEvent (sometimes needed if default contructor was used).*/
  531.     void        MakeAppleEvent( AEEventClass inEventClass, AEEventID inEventID, const AEDesc& inTarget,
  532.                                 AEReturnID inReturnID = kAutoGenerateReturnID, AETransactionID inTransactionID = kAnyTransactionID );
  533.     
  534.     /* Methods to Add Parameters from the AppleEvent */
  535.     OSErr         PutParameterDesc(AEKeyword inKey, const AEDesc& inDesc)
  536.                 {
  537.                     return ::AEPutParamDesc(this, inKey, &inDesc);
  538.                 }
  539.  
  540.     OSErr        PutParameter(AEKeyword inKey, DescType inType, const void* inData, Size inSize)
  541.                 {
  542.                     return ::AEPutParamPtr(this, inKey, inType, inData, inSize);
  543.                 }
  544.     template <typename _Type>
  545.     OSErr        PutParameter(AEKeyword inKey, const _Type & inValue)
  546.                 {
  547.                     return PutParameter(inKey, AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  548.                 }
  549.     template <typename _Type>
  550.     OSErr        PutParameter(AEKeyword inKey, DescType inType, const _Type & inValue)
  551.                 {
  552.                     return PutParameter(inKey, inType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  553.                 }
  554.  
  555.     /* Methods to Retrieve Parameters from the AppleEvent */
  556.     OSErr        GetParameterDesc(AEKeyword inKey, DescType inDesiredType, AEDesc & outDesc) const
  557.                 {
  558.                     return ::AEGetParamDesc(this, inKey, inDesiredType, &outDesc);
  559.                 }
  560.  
  561.     OSErr        GetParameter(AEKeyword inKey, DescType& ioType, void* outData, Size inSize) const
  562.                 {
  563.                     Size actualSize;
  564.                     return ::AEGetParamPtr(this, inKey, ioType, &ioType, outData, inSize, &actualSize);
  565.                 }
  566.     template <typename _Type>
  567.     OSErr        GetParameter(AEKeyword inKey, _Type & outValue) const
  568.                 {
  569.                     DescType type = AEDescriptorTraits<_Type>::kDescriptorType;
  570.                     return GetParameter(inKey, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  571.                 }
  572.     template <typename _Type>
  573.     OSErr        GetParameter(AEKeyword inKey, DescType inType, _Type & outValue) const
  574.                 {
  575.                     DescType type = inType;
  576.                     return GetParameter(inKey, type, &outValue, AEDescriptorTraits<_Type>::GetMaxSize());
  577.                 }
  578.  
  579.     /* Methods to Get Information on Parameters in the AppleEvent */
  580.     Size        GetParameterSize(AEKeyword inKey) const
  581.                 {
  582.                     DescType type;
  583.                     Size actualSize;
  584.                     return ::AESizeOfParam(this, inKey, &type, &actualSize) == noErr
  585.                             ? actualSize
  586.                             : 0;
  587.                 }
  588.  
  589.     /* Methods to Set AppleEvent Attributes */
  590.     OSErr         PutAttributeDesc(AEKeyword inKey, const AEDesc& inDesc)
  591.                 {
  592.                     return ::AEPutAttributeDesc(this, inKey, &inDesc);
  593.                 }
  594.  
  595.     OSErr        PutAttribute(AEKeyword inKey, DescType inType, const void* inData, Size inSize)
  596.                 {
  597.                     return ::AEPutAttributePtr(this, inKey, inType, inData, inSize);
  598.                 }
  599.     template <typename _Type>
  600.     OSErr        PutAttribute(AEKeyword inKey, const _Type & inValue)
  601.                 {
  602.                     return PutAttribute(inKey, AEDescriptorTraits<_Type>::kDescriptorType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  603.                 }
  604.     template <typename _Type>
  605.     OSErr        PutAttribute(AEKeyword inKey, DescType inType, const _Type & inValue)
  606.                 {
  607.                     return PutAttribute(inKey, inType, &inValue, AEDescriptorTraits<_Type>::GetSize(inValue));
  608.                 }
  609.  
  610.     /* Methods to Get AppleEvent Attributes */
  611.     OSErr        GetAttributeDesc(AEKeyword inKeyword, DescType inType, AEDesc & outAttribute) const
  612.                 {
  613.                     return ::AEGetAttributeDesc(this, inKeyword, inType, &outAttribute);
  614.                 }
  615.     OSErr        GetAttribute(AEKeyword inKeyword, DescType inType, void * outData, Size inSize) const
  616.                 {
  617.                     DescType type;
  618.                     Size actualSize;
  619.                     return ::AEGetAttributePtr(this, inKeyword, inType, &type, outData, inSize, &actualSize);
  620.                 }
  621.     template <typename _Type>
  622.     OSErr        GetAttribute(AEKeyword inKeyword, _Type & outData) const
  623.                 {
  624.                     return GetAttribute(inKeyword, AEDescriptorTraits<_Type>::kDescriptorType, &outData, AEDescriptorTraits<_Type>::GetMaxSize());
  625.                 }
  626.     template <typename _Type>
  627.     OSErr        GetAttribute(AEKeyword inKeyword, DescType inType, _Type & outData) const
  628.                 {
  629.                     return GetAttribute(inKeyword, inType, &outData, AEDescriptorTraits<_Type>::GetMaxSize());
  630.                 }
  631.  
  632.     /* Methods to Get Information on Attributes in the AppleEvent */
  633.     Size        GetAttributeSize(AEKeyword inKey) const
  634.                 {
  635.                     DescType type;
  636.                     Size actualSize;
  637.                     return ::AESizeOfAttribute(this, inKey, &type, &actualSize) == noErr
  638.                             ? actualSize
  639.                             : 0;
  640.                 }
  641.  
  642.     /* Miscellaneous Accessors */
  643.     OSErr        GetClass(AEEventClass & outClass) const
  644.                 {
  645.                     DescType type = typeType;
  646.                     return GetAttribute(keyEventClassAttr, type, outClass);
  647.                 }
  648.     OSErr        GetEventID(AEEventID & outID) const
  649.                 {
  650.                     DescType type = typeType;
  651.                     return GetAttribute(keyEventIDAttr, type, outID);
  652.                 }
  653.     OSErr        GetSource(SInt16 & outSource) const
  654.                 {
  655.                     return GetAttribute(keyEventSourceAttr, outSource);
  656.                 }
  657. };
  658.  
  659. /*------------------------------------------------------------------
  660.     AEDescriptorTraits<>
  661. ------------------------------------------------------------------*/
  662.  
  663. // Disallow automatic template instantiation for the following types
  664. DeclareBogusAEDescriptorTrait_(AEDescriptor);
  665. DeclareBogusAEDescriptorTrait_(AEToken);
  666. DeclareBogusAEDescriptorTrait_(AEDescriptorList);
  667. DeclareBogusAEDescriptorTrait_(AEDescriptorRecord);
  668. DeclareBogusAEDescriptorTrait_(AEAppleEvent);
  669.  
  670. /*******************************************************************
  671.     FUNCTIONS
  672. *******************************************************************/
  673.  
  674. #pragma mark -
  675. #pragma mark === FUNCTIONS ===
  676.  
  677. inline AEDescriptor &
  678. GetAEDescriptorOf(AEDesc & inAEDesc)
  679. {
  680.     return static_cast<AEDescriptor &>(inAEDesc);
  681. }
  682. inline const AEDescriptor &
  683. GetAEDescriptorOf(const AEDesc & inAEDesc)
  684. {
  685.     return static_cast<const AEDescriptor &>(inAEDesc);
  686. }
  687.  
  688. inline AEToken &
  689. GetAETokenOf(AEDesc & inAEDesc)
  690. {
  691.     return static_cast<AEToken &>(inAEDesc);
  692. }
  693.  
  694. //        fix me -- the static_cast form apparently constructs an AEToken
  695. //        object when compiled with CW 6.  Note that this fails because
  696. //        the required constructor is private (and unimplemented).
  697. //        AEDescriptor has a constructor, and if it's getting called
  698. //        in the corresponding inline above, there may be a memory leak.
  699.  
  700. inline const AEToken &
  701. GetAETokenOf(const AEDesc & inAEDesc)
  702. {
  703. #if __MWERKS__ >= 0x2400
  704.     return reinterpret_cast<const AEToken &>(inAEDesc);
  705. #else
  706.     return static_cast<const AEToken &>(inAEDesc);
  707. #endif
  708. }
  709.  
  710. inline AEDescriptorList &
  711. GetAEDescriptorListOf(AEDescList & inAEDesc)
  712. {
  713.     return static_cast<AEDescriptorList &>(inAEDesc);
  714. }
  715. inline const AEDescriptorList &
  716. GetAEDescriptorListOf(const AEDescList & inAEDesc)
  717. {
  718.     return static_cast<const AEDescriptorList &>(inAEDesc);
  719. }
  720.  
  721. inline AEDescriptorRecord &
  722. GetAEDescriptorRecordOf(AEDescList & inAEDesc)
  723. {
  724.     return static_cast<AEDescriptorRecord &>(inAEDesc);
  725. }
  726. inline const AEDescriptorRecord &
  727. GetAEDescriptorRecordOf(const AEDescList & inAEDesc)
  728. {
  729.     return static_cast<const AEDescriptorRecord &>(inAEDesc);
  730. }
  731.  
  732. inline AEObjSpecifier &
  733. GetAEObjSpecifierOf(AEDesc & inAEDesc)
  734. {
  735.     return static_cast<AEObjSpecifier &>(inAEDesc);
  736. }
  737. inline const AEObjSpecifier &
  738. GetAEObjSpecifierOf(const AEDesc & inAEDesc)
  739. {
  740.     return static_cast<const AEObjSpecifier &>(inAEDesc);
  741. }
  742.  
  743. inline AEAppleEvent &
  744. GetAEAppleEventOf(AppleEvent & inAppleEvent)
  745. {
  746.     return static_cast<AEAppleEvent &>(inAppleEvent);
  747. }
  748. inline const AEAppleEvent &
  749. GetAEAppleEventOf(const AppleEvent & inAppleEvent)
  750. {
  751.     return static_cast<const AEAppleEvent &>(inAppleEvent);
  752. }
  753.  
  754. /*******************************************************************
  755.     MORE CONSTANTS
  756. *******************************************************************/
  757.  
  758. extern const TAEDescriptor<Boolean>                kAETrueDescriptor;
  759. extern const TAEDescriptor<Boolean>                kAEFalseDescriptor;
  760. extern const TAEDescriptor<ProcessSerialNumber>    kAEThisProcessDescriptor;
  761.  
  762. #pragma options align=reset
  763.  
  764.  
  765. CTX_End_Namespace_MacOS
  766.  
  767.  
  768. /*==================================================================
  769.     Change History (most recent first):
  770.  
  771.     $Log: MacOS_UAppleEvents.h,v $
  772. ==================================================================*/
  773.